*******Libraries*******

library(tswge)
library(tidyverse)
library(ggplot2)
library(tseries)
library(kableExtra)
library(knitr)
library(plotly)
library(vars)
library(vars)
library(nnfor)
library(xts)
library(GGally)
library(astsa)
library(nnfor)
library(forecast)

*******Introduction*******

From Federal Reserve Economic Data, we see GDP changes every year.What is the economic cycle in the US? Are we able to predict the GDP change? Are there any significant variables causing GDP changes? Using Time series will help us analyze the important insights and predict the future trend.

*******Data Source*******

All data was downloaded from Federal Reserve Economic Data (FRED) Repository It contains 75 years quarterly data from 1947 to 2021, 6 variables listed below: 6 columns as below: Date; GDP per capita; Income receipt; gross income; Profit before tax; gdp change. Response variable is gdp change.

# import US GDP data set
df <- read.csv("~/DS 6373 Time Series/TS Project2021/data/usgdp.csv")
df %>%  glimpse()
## Rows: 297
## Columns: 6
## $ DATE              <chr> "1/1/47", "4/1/47", "7/1/47", "10/1/47", "1/1/48", "…
## $ GDP.per.capita    <int> 14203, 14101, 14008, 14161, 14316, 14495, 14515, 144…
## $ Income.receipt    <dbl> 1.444, 1.560, 1.592, 1.792, 1.924, 2.024, 2.132, 2.0…
## $ gross.income      <dbl> 2007.377, 2004.896, 2007.186, 2026.439, 2080.756, 21…
## $ Profit.before.tax <dbl> 30.665, 28.839, 28.431, 30.901, 32.117, 33.664, 32.8…
## $ gdp.change        <dbl> -1.0, -0.8, 6.4, 6.2, 6.8, 2.3, 0.4, -5.4, -1.4, 4.2…
# remove empty data, then plot dgp.change column. We may some outliers in the year 2020, which was during the COVID period. 
df <- na.omit(df)
plot(df$gdp.change)

# We decided to get rid of the outlier which was affected by the COVID in the year 2020. Therefore, we deleted the data from the year 2020.
data <-head(df,-4)
plot(data$gdp.change)

# matrix of scatter plots to check all of variables' correlation. It doesn't show much correlation between gdp change and other 4 variables.However, the top two important variables are GDP.PER.CAPITA and Income.receipt with correlation of -0.2 and -0.194
head(data)
##      DATE GDP.per.capita Income.receipt gross.income Profit.before.tax
## 1  1/1/47          14203          1.444     2007.377            30.665
## 2  4/1/47          14101          1.560     2004.896            28.839
## 3  7/1/47          14008          1.592     2007.186            28.431
## 4 10/1/47          14161          1.792     2026.439            30.901
## 5  1/1/48          14316          1.924     2080.756            32.117
## 6  4/1/48          14495          2.024     2128.912            33.664
##   gdp.change
## 1       -1.0
## 2       -0.8
## 3        6.4
## 4        6.2
## 5        6.8
## 6        2.3
ggpairs(data[2:6]) #matrix of scatter plots

check data stationarity

## $autplt
##  [1]  1.0000000000  0.3553734055  0.2269369119  0.0191933124 -0.0586511988
##  [6] -0.1181742421 -0.0316644626 -0.0424780895 -0.0112454111  0.0823995112
## [11]  0.1032327524  0.0277494350 -0.1025853721 -0.1061111577 -0.0487059751
## [16] -0.0754354491  0.0527465538  0.0512104745  0.1079823850  0.0716927140
## [21]  0.0772534963 -0.0606065204 -0.0488685631 -0.0935929823 -0.0001411832
## [26]  0.0367856683
## 
## $freq
##   [1] 0.003424658 0.006849315 0.010273973 0.013698630 0.017123288 0.020547945
##   [7] 0.023972603 0.027397260 0.030821918 0.034246575 0.037671233 0.041095890
##  [13] 0.044520548 0.047945205 0.051369863 0.054794521 0.058219178 0.061643836
##  [19] 0.065068493 0.068493151 0.071917808 0.075342466 0.078767123 0.082191781
##  [25] 0.085616438 0.089041096 0.092465753 0.095890411 0.099315068 0.102739726
##  [31] 0.106164384 0.109589041 0.113013699 0.116438356 0.119863014 0.123287671
##  [37] 0.126712329 0.130136986 0.133561644 0.136986301 0.140410959 0.143835616
##  [43] 0.147260274 0.150684932 0.154109589 0.157534247 0.160958904 0.164383562
##  [49] 0.167808219 0.171232877 0.174657534 0.178082192 0.181506849 0.184931507
##  [55] 0.188356164 0.191780822 0.195205479 0.198630137 0.202054795 0.205479452
##  [61] 0.208904110 0.212328767 0.215753425 0.219178082 0.222602740 0.226027397
##  [67] 0.229452055 0.232876712 0.236301370 0.239726027 0.243150685 0.246575342
##  [73] 0.250000000 0.253424658 0.256849315 0.260273973 0.263698630 0.267123288
##  [79] 0.270547945 0.273972603 0.277397260 0.280821918 0.284246575 0.287671233
##  [85] 0.291095890 0.294520548 0.297945205 0.301369863 0.304794521 0.308219178
##  [91] 0.311643836 0.315068493 0.318493151 0.321917808 0.325342466 0.328767123
##  [97] 0.332191781 0.335616438 0.339041096 0.342465753 0.345890411 0.349315068
## [103] 0.352739726 0.356164384 0.359589041 0.363013699 0.366438356 0.369863014
## [109] 0.373287671 0.376712329 0.380136986 0.383561644 0.386986301 0.390410959
## [115] 0.393835616 0.397260274 0.400684932 0.404109589 0.407534247 0.410958904
## [121] 0.414383562 0.417808219 0.421232877 0.424657534 0.428082192 0.431506849
## [127] 0.434931507 0.438356164 0.441780822 0.445205479 0.448630137 0.452054795
## [133] 0.455479452 0.458904110 0.462328767 0.465753425 0.469178082 0.472602740
## [139] 0.476027397 0.479452055 0.482876712 0.486301370 0.489726027 0.493150685
## [145] 0.496575342 0.500000000
## 
## $db
##   [1]   4.53538915   4.29314162  -4.14581872   2.85385927  -2.55870129
##   [6]   5.24077026   4.24669914   4.27321187 -20.03873299  -3.74767936
##  [11]   7.37892047 -28.07041056   6.78863916   3.61805411  -2.49737208
##  [16]  -0.07458407   5.75068512   1.85826436  -0.63525231   3.07191046
##  [21]   5.91810637  -4.09421398   1.00691746   1.03882233  -8.86669079
##  [26]   4.97048209   3.67598448   5.34643708   1.29204389  -5.78942970
##  [31]   4.68587870   6.20320433   9.84027135   4.39725913   0.87686514
##  [36]   2.66170198  -3.09747403  -3.79671277  -3.58335613  -4.95225242
##  [41]   0.09910420   2.48934831   0.78512431  -5.16181221   1.19749816
##  [46] -14.97432955  -3.12622384  -3.67577897   0.36751321 -15.77424432
##  [51]  -1.47439622   3.12294814  -2.74558247  -7.85023851   1.20531546
##  [56]  -1.13667658   1.45668175  -2.57093883   0.49213822   0.85187253
##  [61]  -2.18206175   2.68042423   0.60929065  -9.65203865 -15.20043894
##  [66] -15.73753791  -6.55116391  -6.12279144  -3.42543028  -4.64379653
##  [71]  -6.76821837  -3.74811494  -3.35972929  -5.02147456  -8.21081127
##  [76]  -7.94542966 -13.07819858 -18.14412007  -5.14097245  -1.61595215
##  [81]  -2.66235800  -2.63202541  -6.21292492   2.51237717   0.02820428
##  [86]  -3.25312780 -15.41217386  -4.86099153   1.99089355  -6.43719756
##  [91]  -0.61712396  -1.48275387   0.70281439  -6.93774146   0.30418404
##  [96] -18.28103823 -16.42839072  -1.49837570  -5.39339360 -10.09861674
## [101]  -4.23422577 -25.04196059  -5.35798933   3.93959346  -1.82350875
## [106]  -3.89210463  -5.46611623  -5.09501754   1.74053458 -18.32549625
## [111]   1.25991910  -3.02191428  -6.15527178 -29.40994898 -12.45110252
## [116]  -8.12299630  -4.27099329  -3.13555774  -2.20613474 -11.79766337
## [121]  -5.01693223 -13.96455535  -1.13351520  -3.65003829  -1.13676637
## [126]  -2.86179311  -9.20805139 -18.37928353   0.37370700  -0.94686937
## [131]   1.22723848   4.56840085  -6.13595670 -10.01499107  -0.61289981
## [136] -16.81300205 -14.54270675  -0.52503319  -0.37570538 -10.27933569
## [141]  -4.47698374   1.22950906  -2.89308293  -7.22548197   3.68612753
## [146]  -4.38893923
## 
## $dbz
##   [1]  2.6366117  2.6364824  2.6394242  2.6492807  2.6698485  2.7037451
##   [7]  2.7515260  2.8112928  2.8788744  2.9484741  3.0135503  3.0676877
##  [13]  3.1053060  3.1221721  3.1157777  3.0856887  3.0339537  2.9655872
##  [19]  2.8890110  2.8161717  2.7618936  2.7420218  2.7702511  2.8542762
##  [25]  2.9926748  3.1740101  3.3786486  3.5824079  3.7604678  3.8903420
##  [31]  3.9535388  3.9361689  3.8289829  3.6272725  3.3309296  2.9448250
##  [37]  2.4795343  1.9522626  1.3875317  0.8168001  0.2759184 -0.2002584
##  [43] -0.5851551 -0.8665622 -1.0480051 -1.1445570 -1.1758246 -1.1598977
##  [49] -1.1103512 -1.0361989 -0.9435914 -0.8379702 -0.7257824 -0.6153334
##  [55] -0.5167745 -0.4414815 -0.4011603 -0.4069430 -0.4686065 -0.5939232
##  [61] -0.7880847 -1.0531218 -1.3872690 -1.7842872 -2.2328647 -2.7163610
##  [67] -3.2132860 -3.6988798 -4.1477990 -4.5372099 -4.8489935 -5.0700332
##  [73] -5.1909043 -5.2047281 -5.1080295 -4.9037254 -4.6041560 -4.2314761
##  [79] -3.8145152 -3.3836634 -2.9661978 -2.5835066 -2.2503044 -1.9751964
##  [85] -1.7618856 -1.6105348 -1.5190072 -1.4838429 -1.5008775 -1.5654467
##  [91] -1.6721554 -1.8142643 -1.9828516 -2.1660466 -2.3487802 -2.5135839
##  [97] -2.6428273 -2.7222388 -2.7446967 -2.7126646 -2.6380067 -2.5392342
## [103] -2.4374875 -2.3528119 -2.3016268 -2.2954695 -2.3406328 -2.4382518
## [109] -2.5845455 -2.7711151 -2.9853797 -3.2113506 -3.4309607 -3.6260150
## [115] -3.7804963 -3.8825999 -3.9257646 -3.9083495 -3.8322973 -3.7016393
## [121] -3.5216689 -3.2990787 -3.0427200 -2.7642797 -2.4782618 -2.2010826
## [127] -1.9495320 -1.7390412 -1.5821092 -1.4870076 -1.4566986 -1.4878479
## [133] -1.5699265 -1.6846845 -1.8066924 -1.9059724 -1.9534315 -1.9283208
## [139] -1.8247980 -1.6539843 -1.4402693 -1.2141848 -1.0055242 -0.8389309
## [145] -0.7320556 -0.6952933

Condition 1: Constant Mean

  • Wandering and oscillating behavior
  • Only one realization not knowing much
  • The assumption of constant mean seems like not appear to be violated.

Condition 2: Constant Variance

It is tough to confirm whether there is constant variance since we only have one realization. It seems like there is some tendency to make big jumps at the end of the period, indicating non-constant variance over time.

Condition 3: Constant Autocorrelation

The first half of acf seems like little different from the second half of acf, but not much.

# check the 1st half of acf for condition 3
acf(data$gdp.change[1:146])

# check the 2nd half of acf for condition 3
acf(data$gdp.change[147:292])

Conclusion

  • Based on the above analysis, there is some evidence showing non-stationary. But GDP change might be possibly stationary in the long term. We will analyze it using both stationary and non-stationary models.

Stationary model

# AIC selects ARMA(4,3) but BIC picks ARMA(0,2) showing ARMA(4,3) and ARMA(0,2) might be good fitting stationary models. 
aic5.wge(data$gdp.change, p=0:5, q=0:5)
## ---------WORKING... PLEASE WAIT... 
## 
## 
## Five Smallest Values of  aic
##       p    q        aic
## 28    4    3   2.546052
## 23    3    4   2.556459
## 4     0    3   2.557578
## 19    3    0   2.558301
## 3     0    2   2.558863
aic5.wge(data$gdp.change,type = "bic", p=0:5, q=0:5)
## ---------WORKING... PLEASE WAIT... 
## 
## 
## Five Smallest Values of  bic
##       p    q        bic
## 3     0    2   2.596638
## 7     1    0   2.597013
## 13    2    0   2.602604
## 4     0    3   2.607945
## 8     1    1   2.608552
aic5.wge(data$gdp.change,type = "aic", p=0:5, q=0:5)
## ---------WORKING... PLEASE WAIT... 
## 
## 
## Five Smallest Values of  aic
##       p    q        aic
## 28    4    3   2.546052
## 23    3    4   2.556459
## 4     0    3   2.557578
## 19    3    0   2.558301
## 3     0    2   2.558863

Model ID ARMA(4,3)

#aic pick ARMA(4,3), I'll test Stationary model ARMA(4,3)

ARMA43 = est.arma.wge(data$gdp.change,p=4,q=3)
## 
## Coefficients of Original polynomial:  
## 0.8818 0.2219 -1.0225 0.2756 
## 
## Factor                 Roots                Abs Recip    System Freq 
## 1-1.4961B+0.9788B^2    0.7643+-0.6615i      0.9893       0.1135
## 1+0.9203B             -1.0866               0.9203       0.5000
## 1-0.3059B              3.2688               0.3059       0.0000
##   
## 
ljung.wge(ARMA43$res)
## Obs -0.01868356 0.06534016 0.02293769 -0.02010015 0.002663382 0.05627182 0.0008466479 -0.1152143 0.02244328 -0.007274016 0.04180263 -0.1195846 0.01192616 0.0710279 -0.02062347 0.07492956 -0.02260225 -0.006833204 -0.01724831 0.06672934 -0.03941987 0.05665657 -0.03693736 0.03576284
## $test
## [1] "Ljung-Box test"
## 
## $K
## [1] 24
## 
## $chi.square
## [1] 19.20712
## 
## $df
## [1] 24
## 
## $pval
## [1] 0.7408553
ljung.wge(ARMA43$res, K = 48)
## Obs -0.01868356 0.06534016 0.02293769 -0.02010015 0.002663382 0.05627182 0.0008466479 -0.1152143 0.02244328 -0.007274016 0.04180263 -0.1195846 0.01192616 0.0710279 -0.02062347 0.07492956 -0.02260225 -0.006833204 -0.01724831 0.06672934 -0.03941987 0.05665657 -0.03693736 0.03576284 0.03500223 -0.06597338 -0.005565784 0.02668376 0.08388704 -0.1041685 0.04191615 -0.03035224 0.04379716 0.06760999 -0.002961814 -0.02052359 -0.04451 -0.03807524 -0.04292932 0.03676747 -0.06629873 0.1887609 -0.02771618 0.01920448 0.05505401 -0.06396082 0.07580878 0.03925691
## $test
## [1] "Ljung-Box test"
## 
## $K
## [1] 48
## 
## $chi.square
## [1] 51.69399
## 
## $df
## [1] 48
## 
## $pval
## [1] 0.3316212
f_ARMA43 = fore.arma.wge(data$gdp.change,phi = ARMA43$phi,n.ahead = 12,limits = F, lastn = T)

f_ARMA43short = fore.arma.wge(data$gdp.change,phi = ARMA43$phi,n.ahead = 2,limits = F, lastn = T)

ASE_ARMA43 = mean((data$gdp.change[(length(data$gdp.change)-11):length(data$gdp.change)] - f_ARMA43$f)^2)

ASE_ARMA43
## [1] 6.879172
ASE_ARMA43short = mean((data$gdp.change[(length(data$gdp.change)-1):length(data$gdp.change)] - f_ARMA43short$f)^2)

ASE_ARMA43short
## [1] 37.9683
#Compare Spectral Densities
sims = 5
SpecDen = parzen.wge(data$gdp.change, plot = "FALSE")
plot(SpecDen$freq,SpecDen$pzgram, type = "l", lwd = 6)

for( i in 1: sims)
{
   SpecDen2 = parzen.wge(gen.arma.wge(297, phi = ARMA43$phi, plot ="FALSE"), plot = "FALSE")
   lines(SpecDen2$freq,SpecDen2$pzgram, lwd = 2, col = "red")
}

#Compare ACFs
sims = 5
ACF = acf(data$gdp.change, plot = "FALSE")
plot(ACF$lag ,ACF$acf , type = "l", lwd = 6)

for( i in 1: sims)
{
   ACF2 = acf(gen.arma.wge(297, phi = ARMA43$phi, plot = "FALSE"), plot = "FALSE")
   lines(ACF2$lag ,ACF2$acf, lwd = 2, col = "red")
}

#Compare Generated Realizations 


ARMA43gen = gen.arma.wge(297,phi = ARMA43$phi, vara = ARMA43$avar)

plotts.sample.wge(ARMA43gen)

## $autplt
##  [1]  1.00000000  0.72906827  0.15425728 -0.52686538 -0.90004542 -0.86697923
##  [7] -0.38076750  0.24976749  0.77694632  0.89189468  0.59430452 -0.01097494
## [13] -0.58282946 -0.88205916 -0.73188628 -0.24271599  0.36835620  0.77893529
## [19]  0.81370881  0.44420481 -0.12875717 -0.63190891 -0.81460797 -0.59721814
## [25] -0.09252516  0.44991214
## 
## $freq
##   [1] 0.003367003 0.006734007 0.010101010 0.013468013 0.016835017 0.020202020
##   [7] 0.023569024 0.026936027 0.030303030 0.033670034 0.037037037 0.040404040
##  [13] 0.043771044 0.047138047 0.050505051 0.053872054 0.057239057 0.060606061
##  [19] 0.063973064 0.067340067 0.070707071 0.074074074 0.077441077 0.080808081
##  [25] 0.084175084 0.087542088 0.090909091 0.094276094 0.097643098 0.101010101
##  [31] 0.104377104 0.107744108 0.111111111 0.114478114 0.117845118 0.121212121
##  [37] 0.124579125 0.127946128 0.131313131 0.134680135 0.138047138 0.141414141
##  [43] 0.144781145 0.148148148 0.151515152 0.154882155 0.158249158 0.161616162
##  [49] 0.164983165 0.168350168 0.171717172 0.175084175 0.178451178 0.181818182
##  [55] 0.185185185 0.188552189 0.191919192 0.195286195 0.198653199 0.202020202
##  [61] 0.205387205 0.208754209 0.212121212 0.215488215 0.218855219 0.222222222
##  [67] 0.225589226 0.228956229 0.232323232 0.235690236 0.239057239 0.242424242
##  [73] 0.245791246 0.249158249 0.252525253 0.255892256 0.259259259 0.262626263
##  [79] 0.265993266 0.269360269 0.272727273 0.276094276 0.279461279 0.282828283
##  [85] 0.286195286 0.289562290 0.292929293 0.296296296 0.299663300 0.303030303
##  [91] 0.306397306 0.309764310 0.313131313 0.316498316 0.319865320 0.323232323
##  [97] 0.326599327 0.329966330 0.333333333 0.336700337 0.340067340 0.343434343
## [103] 0.346801347 0.350168350 0.353535354 0.356902357 0.360269360 0.363636364
## [109] 0.367003367 0.370370370 0.373737374 0.377104377 0.380471380 0.383838384
## [115] 0.387205387 0.390572391 0.393939394 0.397306397 0.400673401 0.404040404
## [121] 0.407407407 0.410774411 0.414141414 0.417508418 0.420875421 0.424242424
## [127] 0.427609428 0.430976431 0.434343434 0.437710438 0.441077441 0.444444444
## [133] 0.447811448 0.451178451 0.454545455 0.457912458 0.461279461 0.464646465
## [139] 0.468013468 0.471380471 0.474747475 0.478114478 0.481481481 0.484848485
## [145] 0.488215488 0.491582492 0.494949495 0.498316498
## 
## $db
##   [1] -17.722807 -15.780379 -16.540330 -13.337904 -17.735577 -11.198522
##   [7]  -7.106855 -27.106045 -21.264718 -11.109951 -14.892334 -16.881045
##  [13]  -5.115633  -7.121839 -11.055774 -10.522675  -4.318937 -15.904894
##  [19]  -9.956812  -7.641727 -15.152501 -12.040951  -6.996695  -5.695905
##  [25]  -3.784116 -14.113067 -17.195383 -13.319145   2.865567   3.796163
##  [31]   8.024147  -1.243479   6.067702  20.733269   4.602416   3.141551
##  [37]   2.256744  -2.149977  -9.214650  -8.697285 -13.705560  -3.753626
##  [43] -14.560679  -9.723511 -21.075288  -8.759564  -8.429120 -10.095532
##  [49]  -5.510713 -20.041499 -11.503451 -17.954371  -9.520929 -18.764862
##  [55] -11.901209 -12.885425 -15.406435 -12.906907 -11.740363 -17.894979
##  [61] -16.383956 -21.107966 -17.533291 -15.146592 -18.135168 -34.054638
##  [67] -18.161405 -16.172353 -21.927401 -22.736882 -23.962232 -22.274298
##  [73] -18.991745 -20.275329 -29.593486 -19.354959 -29.631677 -38.414244
##  [79] -20.398834 -16.438745 -17.835019 -33.104569 -22.698102 -24.646698
##  [85] -20.086335 -22.367701 -26.599003 -27.074242 -22.120462 -24.712833
##  [91] -19.938057 -22.184299 -25.734010 -18.931053 -22.584082 -17.583097
##  [97] -36.884985 -21.581831 -20.459641 -25.037372 -18.797039 -21.374084
## [103] -36.244720 -30.962083 -29.561485 -24.321200 -49.660321 -21.859959
## [109] -20.987812 -25.823107 -16.952282 -36.065527 -26.423265 -22.665592
## [115] -24.780264 -25.001921 -21.337345 -20.324792 -17.506920 -22.508730
## [121] -28.359951 -22.502793 -20.412486 -17.639898 -21.057668 -25.140551
## [127] -15.804550 -26.005674 -18.200561 -17.810979 -23.169273 -14.234099
## [133] -16.092081 -22.483631 -25.602457 -17.056240 -17.328225 -18.389660
## [139] -17.870707 -14.740040 -10.497871  -5.594182  -8.170840 -13.185264
## [145] -11.296566  -1.185601 -10.199828  -7.893755
## 
## $dbz
##   [1] -14.3195671 -14.0309637 -13.5470157 -12.8994521 -12.1592429 -11.4141080
##   [7] -10.7405150 -10.1886496  -9.7796613  -9.5077107  -9.3429674  -9.2370036
##  [13]  -9.1347007  -8.9930481  -8.7961613  -8.5487504  -8.2406208  -7.7964506
##  [19]  -7.0543152  -5.8464758  -4.1634398  -2.1874529  -0.1451993   1.8060767
##  [25]   3.5868744   5.1660244   6.5361911   7.7002131   8.6644820   9.4359315
##  [31]  10.0207267  10.4237236  10.6482646  10.6961064  10.5673881  10.2605970
##  [37]   9.7725176   9.0981698   8.2307654   7.1617686   5.8812522   4.3790039
##  [43]   2.6474086   0.6883876  -1.4710652  -3.7485213  -5.9655351  -7.8537437
##  [49]  -9.2077944 -10.0722740 -10.6599574 -11.1285720 -11.5043219 -11.7403522
##  [55] -11.8105294 -11.7628705 -11.6989358 -11.7208328 -11.8986690 -12.2647544
##  [61] -12.8178907 -13.5268573 -14.3323455 -15.1537454 -15.9092191 -16.5468855
##  [67] -17.0647205 -17.4975078 -17.8810620 -18.2234389 -18.5008845 -18.6788175
##  [73] -18.7443306 -18.7256361 -18.6828972 -18.6818588 -18.7718380 -18.9763637
##  [79] -19.2926460 -19.6950964 -20.1418592 -20.5854295 -20.9862179 -21.3228383
##  [85] -21.5917091 -21.7959355 -21.9326336 -21.9891701 -21.9518788 -21.8209914
##  [91] -21.6195416 -21.3887728 -21.1744255 -21.0137864 -20.9290093 -20.9263094
##  [97] -20.9986337 -21.1300818 -21.3011503 -21.4938216 -21.6950216 -21.8970625
## [103] -22.0949320 -22.2820274 -22.4469526 -22.5736656 -22.6456605 -22.6524151
## [109] -22.5943253 -22.4828299 -22.3356810 -22.1704642 -21.9998006 -21.8297359
## [115] -21.6608257 -21.4904609 -21.3149563 -21.1304901 -20.9328569 -20.7167990
## [121] -20.4759889 -20.2043479 -19.8984433 -19.5597308 -19.1951130 -18.8150177
## [127] -18.4294677 -18.0434851 -17.6533011 -17.2446317 -16.7941856 -16.2752299
## [133] -15.6665201 -14.9611958 -14.1707972 -13.3220700 -12.4490260 -11.5850013
## [139] -10.7577679  -9.9879569  -9.2895920  -8.6714808  -8.1387021  -7.6938601
## [145]  -7.3380342  -7.0714541  -6.8939587  -6.8052950

Non-stationary model

x=data$gdp.change
#difference the data
xd1.dif=artrans.wge(x,phi.tr=1)

#xd1.dif is the differenced data
plotts.sample.wge(xd1.dif)

## $autplt
##  [1]  1.00000000 -0.39535823  0.06822055 -0.10410317 -0.01189996 -0.12081320
##  [7]  0.07639733 -0.03661057 -0.04446272  0.06174836  0.06867999  0.05658046
## [13] -0.10196805 -0.04498719  0.05933740 -0.12517597  0.10485179 -0.04740600
## [19]  0.06885306 -0.02859393  0.11201004 -0.11853005  0.05674837 -0.11279710
## [25]  0.03126445  0.03690878
## 
## $freq
##   [1] 0.003436426 0.006872852 0.010309278 0.013745704 0.017182131 0.020618557
##   [7] 0.024054983 0.027491409 0.030927835 0.034364261 0.037800687 0.041237113
##  [13] 0.044673540 0.048109966 0.051546392 0.054982818 0.058419244 0.061855670
##  [19] 0.065292096 0.068728522 0.072164948 0.075601375 0.079037801 0.082474227
##  [25] 0.085910653 0.089347079 0.092783505 0.096219931 0.099656357 0.103092784
##  [31] 0.106529210 0.109965636 0.113402062 0.116838488 0.120274914 0.123711340
##  [37] 0.127147766 0.130584192 0.134020619 0.137457045 0.140893471 0.144329897
##  [43] 0.147766323 0.151202749 0.154639175 0.158075601 0.161512027 0.164948454
##  [49] 0.168384880 0.171821306 0.175257732 0.178694158 0.182130584 0.185567010
##  [55] 0.189003436 0.192439863 0.195876289 0.199312715 0.202749141 0.206185567
##  [61] 0.209621993 0.213058419 0.216494845 0.219931271 0.223367698 0.226804124
##  [67] 0.230240550 0.233676976 0.237113402 0.240549828 0.243986254 0.247422680
##  [73] 0.250859107 0.254295533 0.257731959 0.261168385 0.264604811 0.268041237
##  [79] 0.271477663 0.274914089 0.278350515 0.281786942 0.285223368 0.288659794
##  [85] 0.292096220 0.295532646 0.298969072 0.302405498 0.305841924 0.309278351
##  [91] 0.312714777 0.316151203 0.319587629 0.323024055 0.326460481 0.329896907
##  [97] 0.333333333 0.336769759 0.340206186 0.343642612 0.347079038 0.350515464
## [103] 0.353951890 0.357388316 0.360824742 0.364261168 0.367697595 0.371134021
## [109] 0.374570447 0.378006873 0.381443299 0.384879725 0.388316151 0.391752577
## [115] 0.395189003 0.398625430 0.402061856 0.405498282 0.408934708 0.412371134
## [121] 0.415807560 0.419243986 0.422680412 0.426116838 0.429553265 0.432989691
## [127] 0.436426117 0.439862543 0.443298969 0.446735395 0.450171821 0.453608247
## [133] 0.457044674 0.460481100 0.463917526 0.467353952 0.470790378 0.474226804
## [139] 0.477663230 0.481099656 0.484536082 0.487972509 0.491408935 0.494845361
## [145] 0.498281787
## 
## $db
##   [1] -32.40173399 -34.70012543 -24.42062011 -17.89624349 -32.51972455
##   [6] -15.97879243 -12.47433820 -13.90354174 -29.19108291 -20.70801824
##  [11]  -5.72543814 -23.83643217  -5.55052278  -7.25712665 -12.55498645
##  [16]  -9.16402519  -2.87825879  -7.42083430  -7.06191296  -7.04758619
##  [21]  -2.92538719 -12.33441633  -5.11539400  -5.30285598 -13.77919090
##  [26]  -1.29367814  -3.87497500   0.38011221  -5.23894574  -6.65341361
##  [31]  -0.48817880  -0.16686592   5.71872170   0.02718299  -1.56076437
##  [36]  -2.08452017  -5.40054421  -4.57674071  -9.18841233  -9.32890814
##  [41]  -1.89997175  -0.08013195  -2.32125664  -7.67704071   0.39408141
##  [46] -11.74362136  -4.04140825  -3.11420587   0.68615809  -9.46310797
##  [51]  -0.85471750   1.46537004  -5.92688360  -6.13662032   1.07732479
##  [56]  -0.22746784   0.35174394  -3.34972741   0.43700597   4.31347286
##  [61]  -9.67156750   3.63393472   1.16154829  -6.88016445 -14.37925427
##  [66]  -7.78655946  -4.53193008  -5.34023898  -0.76169247  -2.20003638
##  [71]  -8.68463046   0.15978787  -4.73924751  -3.73101127  -6.87470943
##  [76]  -4.27250799  -9.76350072  -8.72823184  -9.65733994   1.20420174
##  [81]  -0.83584714  -0.69127899  -3.29950790   7.24300550  -1.93899229
##  [86]  -1.10798310  -6.05369691   3.47533710   2.06025861   2.48854590
##  [91]   1.47556078   2.42936449   4.26364928 -13.49984108   3.91448201
##  [96]  -1.59007305   1.73379792  -7.83067134  -2.40463890  -4.03209655
## [101]   0.08700636  -4.53440303   4.19117556   7.30875697  -7.78901005
## [106]   3.08048993 -11.87567087  -7.85891172   4.10026007  -8.76326099
## [111]   6.08321359   3.14081363 -10.05025461  -7.89639972 -15.04423804
## [116]  -7.03826687   0.42945128   5.49991565   0.89862504  -1.58560074
## [121] -12.05168340  -9.73760555   6.51100272  -5.46413059  -4.38161718
## [126]   4.38950167  -9.06502759   0.19543119   6.52611569  -0.13773589
## [131]   8.06583688   7.28671294  -4.99191767  -5.44553246   2.53484450
## [136]  -7.16077163  -0.48427091   0.27472142   3.88740717   3.00892824
## [141]   3.94413400   4.86095892  -0.72085882   4.41973229   7.42288794
## 
## $dbz
##   [1] -15.2055454 -14.8969782 -14.4281010 -13.8491446 -13.2071275 -12.5389021
##   [7] -11.8698379 -11.2155270 -10.5844676  -9.9806886  -9.4058922  -8.8609290
##  [13]  -8.3465148  -7.8631759  -7.4105306  -6.9861453  -6.5843345  -6.1953827
##  [19]  -5.8057560  -5.3998095  -4.9631089  -4.4866635  -3.9704944  -3.4248418
##  [25]  -2.8684021  -2.3245421  -1.8172136  -1.3678899  -0.9939260  -0.7080566
##  [31]  -0.5185213  -0.4293736  -0.4406875  -0.5485156  -0.7445524  -1.0155650
##  [37]  -1.3427902  -1.7017107  -2.0628529  -2.3943013  -2.6661419  -2.8558858
##  [43]  -2.9526868  -2.9581885  -2.8836177  -2.7448872  -2.5581319  -2.3371289
##  [49]  -2.0926995  -1.8334135  -1.5667972  -1.3004542  -1.0427774  -0.8031636
##  [55]  -0.5917884  -0.4190841  -0.2950662  -0.2286233  -0.2268262  -0.2942666
##  [61]  -0.4324087  -0.6389464  -0.9072118  -1.2257689  -1.5784431  -1.9451011
##  [67]  -2.3033832  -2.6311854  -2.9090959  -3.1216689  -3.2569238  -3.3047331
##  [73]  -3.2558919  -3.1035137  -2.8467034  -2.4943036  -2.0658491  -1.5886400
##  [79]  -1.0924647  -0.6045704  -0.1465633   0.2665587   0.6258778   0.9272892
##  [85]   1.1700350   1.3553583   1.4854549   1.5628377   1.5901823   1.5706740
##  [91]   1.5088032   1.4114638   1.2890832   1.1563485   1.0319267   0.9365553
##  [97]   0.8892874   0.9026640   0.9786978   1.1077142   1.2707159   1.4440090
## [103]   1.6039748   1.7304959   1.8087056   1.8294935   1.7893759   1.6901831
## [109]   1.5387640   1.3466896   1.1297618   0.9070410   0.6991540   0.5259131
## [115]   0.4037261   0.3436511   0.3508449   0.4254813   0.5643960   0.7623984
## [121]   1.0125848   1.3057690   1.6297404   1.9691267   2.3062166   2.6225427
## [127]   2.9007251   3.1261356   3.2881964   3.3813746   3.4060372   3.3692768
## [133]   3.2856043   3.1770432   3.0717522   3.0001911   2.9886472   3.0518533
## [139]   3.1881812   3.3802379   3.6004484   3.8183733   4.0065589   4.1437181
## [145]   4.2157614
#run aic5.wge with difference data, it selects ARMA(5,1)
aic5.wge(xd1.dif,type = "bic")
## ---------WORKING... PLEASE WAIT... 
## 
## 
## Five Smallest Values of  bic
##       p    q        bic
## 14    4    1   2.695423
## 17    5    1   2.696500
## 11    3    1   2.711637
## 2     0    1   2.741955
## 16    5    0   2.777345
aic5.wge(xd1.dif,type = "aic")
## ---------WORKING... PLEASE WAIT... 
## 
## 
## Five Smallest Values of  aic
##       p    q        aic
## 17    5    1   2.608138
## 14    4    1   2.619684
## 11    3    1   2.648521
## 18    5    2   2.679915
## 16    5    0   2.701606
# AIC and BIC picks p=5, q=1
fitarima=arima(data$gdp.change,order=c(5,1,1),xreg=cbind(data$GDP.per.capita,data$Income.receipt,data$gross.income))
fitarima
## 
## Call:
## arima(x = data$gdp.change, order = c(5, 1, 1), xreg = cbind(data$GDP.per.capita, 
##     data$Income.receipt, data$gross.income))
## 
## Coefficients:
##          ar1     ar2      ar3      ar4      ar5      ma1
##       0.1948  0.0858  -0.1064  -0.1080  -0.1133  -0.6565
## s.e.  0.1620  0.0852   0.0626   0.0683   0.0733   0.2164
##       cbind(data$GDP.per.capita, data$Income.receipt, data$gross.income)1
##                                                                   -0.0056
## s.e.                                                               0.0022
##       cbind(data$GDP.per.capita, data$Income.receipt, data$gross.income)2
##                                                                   -0.0042
## s.e.                                                               0.0095
##       cbind(data$GDP.per.capita, data$Income.receipt, data$gross.income)3
##                                                                    0.0134
## s.e.                                                               0.0048
## 
## sigma^2 estimated as 12.14:  log likelihood = -776.48,  aic = 1572.96
AIC(fitarima) #1718.626
## [1] 1572.964

Model ID ARIMA(5,1,1)

# we get ARIMA(5,1,1)
ARIMA51= est.arma.wge(xd1.dif,p = 5, q=1)
## 
## Coefficients of Original polynomial:  
## 0.3026 0.1466 -0.0844 -0.0606 -0.0857 
## 
## Factor                 Roots                Abs Recip    System Freq 
## 1-1.2394B+0.5441B^2    1.1388+-0.7354i      0.7376       0.0913
## 1+0.5919B             -1.6895               0.5919       0.5000
## 1+0.3448B+0.2662B^2   -0.6478+-1.8269i      0.5159       0.3042
##   
## 
ljung.wge(ARIMA51$res)
## Obs 0.002634967 0.009064809 0.00849656 0.004049856 -0.003994932 0.06028995 -0.04897523 -0.08876154 0.03839984 0.06359548 0.03248956 -0.1345816 -0.06745557 0.01635845 -0.08488485 0.05570062 -0.005203244 0.03356252 0.02156046 0.07203102 -0.07917512 -0.001847757 -0.08297303 0.02357947
## $test
## [1] "Ljung-Box test"
## 
## $K
## [1] 24
## 
## $chi.square
## [1] 22.92076
## 
## $df
## [1] 24
## 
## $pval
## [1] 0.52448
ljung.wge(ARIMA51$res, K = 48)
## Obs 0.002634967 0.009064809 0.00849656 0.004049856 -0.003994932 0.06028995 -0.04897523 -0.08876154 0.03839984 0.06359548 0.03248956 -0.1345816 -0.06745557 0.01635845 -0.08488485 0.05570062 -0.005203244 0.03356252 0.02156046 0.07203102 -0.07917512 -0.001847757 -0.08297303 0.02357947 0.03117027 -0.04955074 -0.004059025 0.06165664 0.06731381 -0.11971 -0.01954801 -0.05669516 0.008625194 0.06457581 -0.009322939 -0.004319998 -0.02518473 -0.02670933 -0.0501059 -0.01874689 -0.09886988 0.1521388 -0.04148955 0.02224686 0.07596727 -0.0261956 0.07487633 0.02626075
## $test
## [1] "Ljung-Box test"
## 
## $K
## [1] 48
## 
## $chi.square
## [1] 51.92725
## 
## $df
## [1] 48
## 
## $pval
## [1] 0.3234607
f_arima511=fore.arma.wge(data$gdp.change,phi=ARIMA51$phi,n.ahead = 12,limits = F, lastn = T)

f_arima511short=fore.arma.wge(data$gdp.change,phi=ARIMA51$phi,n.ahead = 2,limits = F, lastn = T)

ASElong = mean((data$gdp.change[(length(data$gdp.change)-11):length(data$gdp.change)] - f_arima511$f)^2)

ASElong
## [1] 6.515806
ASEshort = mean((data$gdp.change[(length(data$gdp.change)-1):length(data$gdp.change)] - f_arima511short$f)^2)

ASEshort
## [1] 35.09099
ASE = mean((data$gdp.change[(length(data$gdp.change)-11):length(data$gdp.change)] - f_arima511$f)^2)

ASE
## [1] 6.515806
#Compare Spectral Densities
sims = 5
SpecDen = parzen.wge(data$gdp.change, plot = "FALSE")
plot(SpecDen$freq,SpecDen$pzgram, type = "l", lwd = 6)

for( i in 1: sims)
{
   SpecDen3= parzen.wge(gen.arma.wge(295, phi = ARIMA51$phi, plot ="FALSE"), plot = "FALSE")
   lines(SpecDen3$freq,SpecDen3$pzgram, lwd = 2, col = "red")
}

#Compare ARIMA51 ACFs
sims = 5
ACF = acf(data$gdp.change, plot = "FALSE")
plot(ACF$lag ,ACF$acf , type = "l", lwd = 6)

for( i in 1: sims)
{
   ACF2 = acf(gen.aruma.wge(319, phi = ARIMA51$phi, plot ="FALSE"), plot = "FALSE")
   lines(ACF2$lag ,ACF2$acf, lwd = 2, col = "red")
}

#Compare Generated Realizations 
ARIMA51gen = gen.aruma.wge(297,phi = ARIMA51$phi, vara = ARIMA51$avar)

plotts.sample.wge(ARIMA51gen)

## $autplt
##  [1]  1.00000000  0.39420952  0.26526097  0.02640541  0.03210965 -0.10050527
##  [7] -0.10120300 -0.02522904 -0.07175427 -0.09186705 -0.15110016 -0.12755790
## [13] -0.20458737 -0.12920343 -0.07684574  0.08215468  0.03093450  0.05443022
## [19]  0.02647287  0.04961930  0.07136296  0.10197579  0.09564815 -0.01808792
## [25] -0.01178745 -0.06741017
## 
## $freq
##   [1] 0.003367003 0.006734007 0.010101010 0.013468013 0.016835017 0.020202020
##   [7] 0.023569024 0.026936027 0.030303030 0.033670034 0.037037037 0.040404040
##  [13] 0.043771044 0.047138047 0.050505051 0.053872054 0.057239057 0.060606061
##  [19] 0.063973064 0.067340067 0.070707071 0.074074074 0.077441077 0.080808081
##  [25] 0.084175084 0.087542088 0.090909091 0.094276094 0.097643098 0.101010101
##  [31] 0.104377104 0.107744108 0.111111111 0.114478114 0.117845118 0.121212121
##  [37] 0.124579125 0.127946128 0.131313131 0.134680135 0.138047138 0.141414141
##  [43] 0.144781145 0.148148148 0.151515152 0.154882155 0.158249158 0.161616162
##  [49] 0.164983165 0.168350168 0.171717172 0.175084175 0.178451178 0.181818182
##  [55] 0.185185185 0.188552189 0.191919192 0.195286195 0.198653199 0.202020202
##  [61] 0.205387205 0.208754209 0.212121212 0.215488215 0.218855219 0.222222222
##  [67] 0.225589226 0.228956229 0.232323232 0.235690236 0.239057239 0.242424242
##  [73] 0.245791246 0.249158249 0.252525253 0.255892256 0.259259259 0.262626263
##  [79] 0.265993266 0.269360269 0.272727273 0.276094276 0.279461279 0.282828283
##  [85] 0.286195286 0.289562290 0.292929293 0.296296296 0.299663300 0.303030303
##  [91] 0.306397306 0.309764310 0.313131313 0.316498316 0.319865320 0.323232323
##  [97] 0.326599327 0.329966330 0.333333333 0.336700337 0.340067340 0.343434343
## [103] 0.346801347 0.350168350 0.353535354 0.356902357 0.360269360 0.363636364
## [109] 0.367003367 0.370370370 0.373737374 0.377104377 0.380471380 0.383838384
## [115] 0.387205387 0.390572391 0.393939394 0.397306397 0.400673401 0.404040404
## [121] 0.407407407 0.410774411 0.414141414 0.417508418 0.420875421 0.424242424
## [127] 0.427609428 0.430976431 0.434343434 0.437710438 0.441077441 0.444444444
## [133] 0.447811448 0.451178451 0.454545455 0.457912458 0.461279461 0.464646465
## [139] 0.468013468 0.471380471 0.474747475 0.478114478 0.481481481 0.484848485
## [145] 0.488215488 0.491582492 0.494949495 0.498316498
## 
## $db
##   [1]  -8.32789440   0.33462075   2.22992638  -0.43816326   4.10569628
##   [6]   3.67896664  -2.02712973   3.12704287   5.36775061  -2.31005486
##  [11]  -3.82658277   5.45720532   8.90235101  -3.59371716  10.68145478
##  [16]   4.56479411   2.95978310  -0.80321509   6.73418716   3.65354190
##  [21]  -1.32062570  -1.89912063   5.59497349  -2.03569655  -8.98322776
##  [26]   0.94393242  -1.02211724   3.84554373   1.50408952   5.30141665
##  [31] -13.69280278   2.94862434   0.86998824  -0.02872617   6.98478374
##  [36]   4.36234726  -0.08005701  -8.00011805  -9.16376709   2.82479159
##  [41]   4.64063966   5.74741288   4.27404715  -8.36936946  -7.87247854
##  [46]  -3.09629275 -10.87123040  -4.79680793  -7.57990033  -4.60045897
##  [51]  -4.47785535  -8.22651624 -17.56914236   4.35237830  -0.31551557
##  [56]  -6.48781054  -0.50969966  -2.54042289   0.86069823   1.14260393
##  [61] -11.74527972   0.92766916  -8.51917702  -3.21031842  -9.46488118
##  [66] -10.06089020  -1.83716932  -1.08199097 -13.50380302   0.09506812
##  [71]  -3.07110316  -0.76776432  -7.87296815   1.59755783 -10.11947248
##  [76]  -1.72182415 -10.02703638   1.68374722  -2.23957451  -0.87971353
##  [81] -13.11166067   5.40538896 -12.75059997  -8.88561296 -15.21517969
##  [86]   2.52362184  -2.73323946  -7.39245813  -4.58262355 -11.55110954
##  [91]  -6.34526564 -13.82476275  -6.86216590  -2.17674049  -1.28368750
##  [96]  -4.35577621  -8.11389188 -11.53252706  -4.77938733  -5.95942263
## [101]  -1.19214184  -7.25401990  -1.90651837 -22.57952057 -12.21754378
## [106] -17.85430582  -2.64588923  -3.87826677 -12.99872118  -7.22028860
## [111]  -4.62925774  -6.89560989  -0.91674656  -2.24534967 -10.35972262
## [116] -12.33113033 -16.33225775  -5.41516075   1.39321235  -2.54798050
## [121] -18.40180472  -6.66681388  -2.59132767  -6.47198476   1.75159376
## [126]  -8.19558467  -0.18600938 -13.84129982 -13.97720035  -3.13983960
## [131]  -8.08662879   0.80789846   0.63040592  -9.27598601  -3.74044750
## [136]   0.44529556   5.47844823   1.21170927  -5.63280609 -12.34310698
## [141]  -0.94050443  -0.40943426  -0.20102961  -0.33029281  -0.85293176
## [146]  -5.91130845 -10.57635130  -3.51355011
## 
## $dbz
##   [1]  0.9866247  1.1493266  1.4074737  1.7436188  2.1367815  2.5646232
##   [7]  3.0051688  3.4379712  3.8447834  4.2098701  4.5200867  4.7648336
##  [13]  4.9359676  5.0277392  5.0368085  4.9623923  4.8065824  4.5748617
##  [19]  4.2768001  3.9268169  3.5447261  3.1555375  2.7878060  2.4700064
##  [25]  2.2252808  2.0662843  1.9925999  1.9921613  2.0458158  2.1326106
##  [31]  2.2337024  2.3341478  2.4229390  2.4920463  2.5351387  2.5464322
##  [37]  2.5198997  2.4489316  2.3264319  2.1452934  1.8991953  1.5837138
##  [43]  1.1978092  0.7457990  0.2398742 -0.2971123 -0.8297003 -1.3111708
##  [49] -1.6913871 -1.9317304 -2.0207699 -1.9796422 -1.8526558 -1.6906633
##  [55] -1.5377631 -1.4254276 -1.3721753 -1.3855864 -1.4646151 -1.6014332
##  [61] -1.7827822 -1.9911345 -2.2060618 -2.4061421 -2.5714739 -2.6864292
##  [67] -2.7418702 -2.7360174 -2.6736499 -2.5640666 -2.4187021 -2.2492160
##  [73] -2.0664407 -1.8801307 -1.6992081 -1.5321600 -1.3873299 -1.2729720
##  [79] -1.1970560 -1.1668763 -1.1885443 -1.2664290 -1.4025797 -1.5961522
##  [85] -1.8428656 -2.1345657 -2.4590603 -2.8004923 -3.1405674 -3.4608184
##  [91] -3.7456768 -3.9855358 -4.1786323 -4.3308883 -4.4537810 -4.5611779
##  [97] -4.6662818 -4.7794121 -4.9067637 -5.0499276 -5.2058860 -5.3673178
## [103] -5.5232266 -5.6600488 -5.7634051 -5.8204558 -5.8224286 -5.7665227
## [109] -5.6564108 -5.5010795 -5.3124922 -5.1029927 -4.8832849 -4.6614063
## [115] -4.4426821 -4.2303832 -4.0266963 -3.8336118 -3.6534086 -3.4885509
## [121] -3.3409939 -3.2110674 -3.0962389 -2.9901550 -2.8824274 -2.7596298
## [127] -2.6077637 -2.4158982 -2.1798930 -1.9046499 -1.6038028 -1.2970306
## [133] -1.0062788 -0.7523259 -0.5524852 -0.4194828 -0.3611469 -0.3804836
## [139] -0.4758399 -0.6410117 -0.8652989 -1.1336244 -1.4269169 -1.7229890
## [145] -1.9980670 -2.2289362 -2.3953992 -2.4825701

Model ID ARUMA(5,1,0) S=27

# overfit for seasonality, we get system frequency 0.02 associated with period 27. 
plotts.sample.wge(x)

## $autplt
##  [1]  1.0000000000  0.3553734055  0.2269369119  0.0191933124 -0.0586511988
##  [6] -0.1181742421 -0.0316644626 -0.0424780895 -0.0112454111  0.0823995112
## [11]  0.1032327524  0.0277494350 -0.1025853721 -0.1061111577 -0.0487059751
## [16] -0.0754354491  0.0527465538  0.0512104745  0.1079823850  0.0716927140
## [21]  0.0772534963 -0.0606065204 -0.0488685631 -0.0935929823 -0.0001411832
## [26]  0.0367856683
## 
## $freq
##   [1] 0.003424658 0.006849315 0.010273973 0.013698630 0.017123288 0.020547945
##   [7] 0.023972603 0.027397260 0.030821918 0.034246575 0.037671233 0.041095890
##  [13] 0.044520548 0.047945205 0.051369863 0.054794521 0.058219178 0.061643836
##  [19] 0.065068493 0.068493151 0.071917808 0.075342466 0.078767123 0.082191781
##  [25] 0.085616438 0.089041096 0.092465753 0.095890411 0.099315068 0.102739726
##  [31] 0.106164384 0.109589041 0.113013699 0.116438356 0.119863014 0.123287671
##  [37] 0.126712329 0.130136986 0.133561644 0.136986301 0.140410959 0.143835616
##  [43] 0.147260274 0.150684932 0.154109589 0.157534247 0.160958904 0.164383562
##  [49] 0.167808219 0.171232877 0.174657534 0.178082192 0.181506849 0.184931507
##  [55] 0.188356164 0.191780822 0.195205479 0.198630137 0.202054795 0.205479452
##  [61] 0.208904110 0.212328767 0.215753425 0.219178082 0.222602740 0.226027397
##  [67] 0.229452055 0.232876712 0.236301370 0.239726027 0.243150685 0.246575342
##  [73] 0.250000000 0.253424658 0.256849315 0.260273973 0.263698630 0.267123288
##  [79] 0.270547945 0.273972603 0.277397260 0.280821918 0.284246575 0.287671233
##  [85] 0.291095890 0.294520548 0.297945205 0.301369863 0.304794521 0.308219178
##  [91] 0.311643836 0.315068493 0.318493151 0.321917808 0.325342466 0.328767123
##  [97] 0.332191781 0.335616438 0.339041096 0.342465753 0.345890411 0.349315068
## [103] 0.352739726 0.356164384 0.359589041 0.363013699 0.366438356 0.369863014
## [109] 0.373287671 0.376712329 0.380136986 0.383561644 0.386986301 0.390410959
## [115] 0.393835616 0.397260274 0.400684932 0.404109589 0.407534247 0.410958904
## [121] 0.414383562 0.417808219 0.421232877 0.424657534 0.428082192 0.431506849
## [127] 0.434931507 0.438356164 0.441780822 0.445205479 0.448630137 0.452054795
## [133] 0.455479452 0.458904110 0.462328767 0.465753425 0.469178082 0.472602740
## [139] 0.476027397 0.479452055 0.482876712 0.486301370 0.489726027 0.493150685
## [145] 0.496575342 0.500000000
## 
## $db
##   [1]   4.53538915   4.29314162  -4.14581872   2.85385927  -2.55870129
##   [6]   5.24077026   4.24669914   4.27321187 -20.03873299  -3.74767936
##  [11]   7.37892047 -28.07041056   6.78863916   3.61805411  -2.49737208
##  [16]  -0.07458407   5.75068512   1.85826436  -0.63525231   3.07191046
##  [21]   5.91810637  -4.09421398   1.00691746   1.03882233  -8.86669079
##  [26]   4.97048209   3.67598448   5.34643708   1.29204389  -5.78942970
##  [31]   4.68587870   6.20320433   9.84027135   4.39725913   0.87686514
##  [36]   2.66170198  -3.09747403  -3.79671277  -3.58335613  -4.95225242
##  [41]   0.09910420   2.48934831   0.78512431  -5.16181221   1.19749816
##  [46] -14.97432955  -3.12622384  -3.67577897   0.36751321 -15.77424432
##  [51]  -1.47439622   3.12294814  -2.74558247  -7.85023851   1.20531546
##  [56]  -1.13667658   1.45668175  -2.57093883   0.49213822   0.85187253
##  [61]  -2.18206175   2.68042423   0.60929065  -9.65203865 -15.20043894
##  [66] -15.73753791  -6.55116391  -6.12279144  -3.42543028  -4.64379653
##  [71]  -6.76821837  -3.74811494  -3.35972929  -5.02147456  -8.21081127
##  [76]  -7.94542966 -13.07819858 -18.14412007  -5.14097245  -1.61595215
##  [81]  -2.66235800  -2.63202541  -6.21292492   2.51237717   0.02820428
##  [86]  -3.25312780 -15.41217386  -4.86099153   1.99089355  -6.43719756
##  [91]  -0.61712396  -1.48275387   0.70281439  -6.93774146   0.30418404
##  [96] -18.28103823 -16.42839072  -1.49837570  -5.39339360 -10.09861674
## [101]  -4.23422577 -25.04196059  -5.35798933   3.93959346  -1.82350875
## [106]  -3.89210463  -5.46611623  -5.09501754   1.74053458 -18.32549625
## [111]   1.25991910  -3.02191428  -6.15527178 -29.40994898 -12.45110252
## [116]  -8.12299630  -4.27099329  -3.13555774  -2.20613474 -11.79766337
## [121]  -5.01693223 -13.96455535  -1.13351520  -3.65003829  -1.13676637
## [126]  -2.86179311  -9.20805139 -18.37928353   0.37370700  -0.94686937
## [131]   1.22723848   4.56840085  -6.13595670 -10.01499107  -0.61289981
## [136] -16.81300205 -14.54270675  -0.52503319  -0.37570538 -10.27933569
## [141]  -4.47698374   1.22950906  -2.89308293  -7.22548197   3.68612753
## [146]  -4.38893923
## 
## $dbz
##   [1]  2.6366117  2.6364824  2.6394242  2.6492807  2.6698485  2.7037451
##   [7]  2.7515260  2.8112928  2.8788744  2.9484741  3.0135503  3.0676877
##  [13]  3.1053060  3.1221721  3.1157777  3.0856887  3.0339537  2.9655872
##  [19]  2.8890110  2.8161717  2.7618936  2.7420218  2.7702511  2.8542762
##  [25]  2.9926748  3.1740101  3.3786486  3.5824079  3.7604678  3.8903420
##  [31]  3.9535388  3.9361689  3.8289829  3.6272725  3.3309296  2.9448250
##  [37]  2.4795343  1.9522626  1.3875317  0.8168001  0.2759184 -0.2002584
##  [43] -0.5851551 -0.8665622 -1.0480051 -1.1445570 -1.1758246 -1.1598977
##  [49] -1.1103512 -1.0361989 -0.9435914 -0.8379702 -0.7257824 -0.6153334
##  [55] -0.5167745 -0.4414815 -0.4011603 -0.4069430 -0.4686065 -0.5939232
##  [61] -0.7880847 -1.0531218 -1.3872690 -1.7842872 -2.2328647 -2.7163610
##  [67] -3.2132860 -3.6988798 -4.1477990 -4.5372099 -4.8489935 -5.0700332
##  [73] -5.1909043 -5.2047281 -5.1080295 -4.9037254 -4.6041560 -4.2314761
##  [79] -3.8145152 -3.3836634 -2.9661978 -2.5835066 -2.2503044 -1.9751964
##  [85] -1.7618856 -1.6105348 -1.5190072 -1.4838429 -1.5008775 -1.5654467
##  [91] -1.6721554 -1.8142643 -1.9828516 -2.1660466 -2.3487802 -2.5135839
##  [97] -2.6428273 -2.7222388 -2.7446967 -2.7126646 -2.6380067 -2.5392342
## [103] -2.4374875 -2.3528119 -2.3016268 -2.2954695 -2.3406328 -2.4382518
## [109] -2.5845455 -2.7711151 -2.9853797 -3.2113506 -3.4309607 -3.6260150
## [115] -3.7804963 -3.8825999 -3.9257646 -3.9083495 -3.8322973 -3.7016393
## [121] -3.5216689 -3.2990787 -3.0427200 -2.7642797 -2.4782618 -2.2010826
## [127] -1.9495320 -1.7390412 -1.5821092 -1.4870076 -1.4566986 -1.4878479
## [133] -1.5699265 -1.6846845 -1.8066924 -1.9059724 -1.9534315 -1.9283208
## [139] -1.8247980 -1.6539843 -1.4402693 -1.2141848 -1.0055242 -0.8389309
## [145] -0.7320556 -0.6952933
est.ar.wge(data$gdp.change,p = 12) 
## 
## Coefficients of Original polynomial:  
## 0.3141 0.1840 -0.0661 -0.0679 -0.0820 0.0904 -0.0460 -0.0585 0.0865 0.0954 -0.0026 -0.1755 
## 
## Factor                 Roots                Abs Recip    System Freq 
## 1-1.4059B+0.8259B^2    0.8511+-0.6974i      0.9088       0.1093
## 1-0.5698B+0.7862B^2    0.3624+-1.0680i      0.8867       0.1979
## 1+0.5302B+0.7457B^2   -0.3555+-1.1021i      0.8636       0.2997
## 1-1.6762B+0.7418B^2    1.1298+-0.2675i      0.8613       0.0370
## 1+1.6592B+0.7279B^2   -1.1397+-0.2736i      0.8532       0.4625
## 1+1.1485B+0.6711B^2   -0.8556+-0.8706i      0.8192       0.3736
##   
##   
## 
## Coefficients of Original polynomial:  
## 0.3141 0.1840 -0.0661 -0.0679 -0.0820 0.0904 -0.0460 -0.0585 0.0865 0.0954 -0.0026 -0.1755 
## 
## Factor                 Roots                Abs Recip    System Freq 
## 1-1.4059B+0.8259B^2    0.8511+-0.6974i      0.9088       0.1093
## 1-0.5698B+0.7862B^2    0.3624+-1.0680i      0.8867       0.1979
## 1+0.5302B+0.7457B^2   -0.3555+-1.1021i      0.8636       0.2997
## 1-1.6762B+0.7418B^2    1.1298+-0.2675i      0.8613       0.0370
## 1+1.6592B+0.7279B^2   -1.1397+-0.2736i      0.8532       0.4625
## 1+1.1485B+0.6711B^2   -0.8556+-0.8706i      0.8192       0.3736
##   
## 
## $phi
##  [1]  0.314069511  0.184020866 -0.066080984 -0.067940844 -0.081972592
##  [6]  0.090375734 -0.045990923 -0.058470179  0.086480690  0.095363038
## [11] -0.002610369 -0.175483206
## 
## $res
##   [1] -2.15359860 -2.07598972  4.23624661  1.79039761  1.02353242 -2.59234854
##   [7] -2.52389829 -6.29125812 -1.00432837  4.14738663 -6.40877986 13.91327758
##  [13]  4.72957860  6.28154026 -0.50476007 -0.51268863  6.96319858  5.25307814
##  [19] -3.90258753  0.64451344 -2.01239257 -0.41655565  8.34875561  1.43868167
##  [25] -1.75209743 -3.79529432 -6.26008643  0.02062483  0.20427104  3.34657360
##  [31]  4.26806960  5.68030889 -1.86271033 -0.90538414  0.70541720 -2.11294224
##  [37]  3.57603914 -3.08341258  3.35660956 -2.39808811 -6.48191956  1.85628667
##  [43] -6.80108196 -9.62375566  5.35581744  9.08248080  3.99075137 -1.11256149
##  [49]  2.93243839 -4.14945867 -1.07448630  7.62897837 -5.40862331  1.19273737
##  [55] -8.58675150 -0.46971039  4.85709866  1.90229789  3.50952359  2.77606147
##  [61] -0.03529566  0.81795689 -2.14277705  3.79442697  1.76400122  4.90861290
##  [67] -4.37739213  3.78599050  0.32209457  2.61442603 -1.92002065  7.57255579
##  [73]  1.46820425  4.24597073  3.79182612  4.04661133 -3.78797120  0.37607765
##  [79]  1.30093701  1.99159199 -3.03351974  1.11647509  0.04304231  5.38807081
##  [85]  1.03346292 -1.87547307 -0.28225566  5.32662989 -2.51406124 -0.44265376
##  [91] -4.31979083 -1.63173864 -0.95909353  0.41591247 -7.83380618 10.70915943
##  [97] -1.77674586 -1.80422894 -2.33563168  5.65442250  6.86116176 -2.92633946
## [103]  1.85807568  6.69958197 -1.17026024 -7.29034331  1.14502979 -2.83708097
## [109] -0.19021689 -6.58251807 -3.54402543 -4.42358629  1.84061367  4.06966639
## [115]  0.70497794  5.58356127 -2.26031903 -1.66486617  1.21539433  1.55826179
## [121]  5.47311059  1.65100721 -6.09687349 -2.77993673 14.31496060 -2.52244964
## [127] -0.24837444 -1.76643177 -1.00726180  1.97549566 -3.87925331 -0.73970535
## [133] -8.66399765 -0.05389442  5.81581254  2.29217607 -7.27199878  2.56005856
## [139] -5.09285526 -7.47239531  1.66579532 -2.75762252 -0.19950060  2.13600978
## [145]  2.47915634  2.04798482  2.75716864  3.75892737  2.74063388  0.46799637
## [151] -1.15726831  0.62167030  0.83168250  1.65341146 -2.44640284  0.06869586
## [157] -0.84060130  1.33661824 -0.14568867  0.51467019  2.25744722 -0.02490905
## [163]  3.34010714 -2.58769834  2.03179010 -0.30116241  2.13452414  0.89086160
## [169] -1.15701518  0.27911131 -2.50432000  1.96012748 -1.72962665 -2.80230032
## [175] -4.95938944 -2.87865185  2.95724366 -1.47485726 -1.96138918  2.23532204
## [181]  1.00348249 -0.10564480 -0.20295620 -2.01830914  0.88073042 -0.67065702
## [187]  1.71860553 -0.48975332  1.33931724 -1.80243023  0.97525107 -1.64429013
## [193] -1.53101808  1.93773789  0.03778953 -0.52058390  3.01731963 -1.15837150
## [199]  0.66252625 -0.93857576  4.22994873  1.50359993 -0.82388938  0.56121747
## [205]  0.45111059  1.88735350  2.18253299 -0.86892833  0.20076723  2.30089881
## [211]  3.27097010 -3.34685307  4.67595792 -2.92763966 -0.24171375 -3.56346497
## [217]  0.14983451 -2.97503984 -0.77063866  1.39208744 -1.26061388 -1.35925765
## [223] -2.20344290  0.06984580  2.08877217  3.16542479  0.23784868 -2.41741783
## [229]  0.28722431  0.27619794  0.69650660  0.99086331 -1.66118634  0.87432198
## [235] -1.04080098  1.62164555 -2.87474245 -1.65305990  2.14010799 -2.28347409
## [241] -0.58348991 -0.73167478 -0.02565988 -4.77625103 -0.18614761 -3.98829425
## [247] -9.87353305 -2.95395180 -0.41498137 -0.06196149  0.84761052 -3.64232649
## [253]  0.93804298 -0.08479094 -1.63615567 -3.67242162  2.27477053 -2.26300405
## [259]  0.63747793 -1.60489213 -2.86379206 -2.22721261 -1.77277310  1.64809692
## [265] -2.33438759  0.56855061  0.44895754 -5.03566138  3.34239206  0.89866501
## [271] -1.41369832  0.81225515 -0.79063530 -1.28419009 -2.45420994 -0.06709437
## [277] -1.02462776 -0.33044649 -0.76311446 -1.55791481 -0.77294672  0.24339743
## [283]  0.91259213  0.67374449 -0.85827674 -1.20004182 -1.52287584  0.47748239
## [289] -1.65510830 -0.23877178 -0.36557741 -8.19436336
## 
## $avar
## [1] 11.73459
## 
## $aic
## [1] 2.551582
## 
## $aicc
## [1] 3.563624
## 
## $bic
## [1] 2.715273
factor.wge(data$gdp.change)
## 
## Coefficients of Original polynomial:  
## -1.0000 -0.8000 6.4000 6.2000 6.8000 2.3000 0.4000 -5.4000 -1.4000 4.2000 -3.3000 16.7000 12.8000 16.4000 7.9000 5.5000 7.1000 8.5000 0.9000 4.3000 0.9000 2.9000 13.8000 7.6000 3.1000 -2.2000 -5.9000 -1.9000 0.4000 4.6000 8.1000 11.9000 6.7000 5.5000 2.4000 -1.5000 3.3000 -0.4000 6.7000 2.6000 -0.9000 4.0000 -4.1000 -10.0000 2.7000 9.6000 9.7000 7.9000 9.3000 0.3000 1.1000 9.3000 -2.1000 2.0000 -5.0000 2.7000 7.0000 7.9000 8.1000 7.3000 3.7000 5.0000 1.3000 4.4000 4.6000 9.1000 2.6000 8.7000 4.4000 6.4000 1.2000 10.0000 5.1000 9.2000 9.5000 10.1000 1.4000 3.4000 3.3000 3.6000 0.2000 3.8000 3.0000 8.4000 6.9000 3.1000 1.6000 6.4000 1.2000 2.7000 -1.9000 -0.6000 0.6000 3.7000 -4.2000 11.3000 2.2000 3.3000 0.9000 7.6000 9.4000 3.8000 6.9000 10.3000 4.4000 -2.1000 3.8000 -3.4000 1.0000 -3.7000 -1.5000 -4.8000 2.9000 7.0000 5.5000 9.3000 3.0000 2.2000 2.9000 4.8000 8.0000 7.4000 0.0000 1.3000 16.4000 4.1000 5.5000 0.7000 0.4000 3.0000 1.0000 1.3000 -8.0000 -0.5000 7.7000 8.1000 -2.9000 4.9000 -4.3000 -6.1000 1.8000 -1.5000 0.2000 5.4000 9.4000 8.2000 8.6000 8.1000 7.1000 3.9000 3.3000 3.9000 3.6000 6.2000 3.0000 3.8000 1.8000 3.9000 2.2000 3.0000 4.4000 3.5000 7.0000 2.1000 5.4000 2.4000 5.4000 4.1000 3.1000 3.0000 0.8000 4.4000 1.5000 0.3000 -3.6000 -1.9000 3.2000 2.0000 1.4000 4.9000 4.4000 4.0000 4.2000 0.7000 2.3000 1.9000 5.6000 3.9000 5.5000 2.4000 4.7000 1.4000 1.2000 3.5000 2.7000 3.0000 6.8000 3.6000 4.2000 2.6000 6.8000 5.1000 3.5000 4.1000 3.8000 5.1000 6.6000 3.8000 3.1000 5.3000 7.0000 1.5000 7.5000 0.5000 2.5000 -1.1000 2.4000 -1.7000 1.1000 3.5000 2.4000 1.8000 0.6000 2.2000 3.5000 7.0000 4.7000 2.2000 3.1000 3.8000 4.1000 4.5000 1.9000 3.6000 2.6000 5.4000 0.9000 0.6000 3.5000 0.9000 2.3000 2.2000 2.5000 -2.3000 2.1000 -2.1000 -8.4000 -4.4000 -0.6000 1.5000 4.5000 1.5000 3.7000 3.0000 2.0000 -1.0000 2.9000 -0.1000 4.7000 3.2000 1.7000 0.5000 0.5000 3.6000 0.5000 3.2000 3.2000 -1.1000 5.5000 5.0000 2.3000 3.8000 2.7000 1.5000 0.6000 2.3000 1.3000 2.2000 2.5000 2.3000 1.7000 2.9000 3.9000 3.8000 2.7000 2.1000 1.3000 2.9000 1.5000 2.6000 2.4000 -5.0000 
## 
## Factor                 Roots                Abs Recip    System Freq 
## 1-1.8896B              0.5292               1.8896       0.0000
## 1+1.9433B+3.5320B^2   -0.2751+-0.4555i      1.8794       0.3365
## 1+1.9422B+1.6237B^2   -0.5981+-0.5081i      1.2742       0.3879
## 1+0.0375B+1.2902B^2   -0.0145+-0.8803i      1.1359       0.2526
## 1+1.1327B             -0.8828               1.1327       0.5000
## 1-0.9560B+1.1640B^2    0.4106+-0.8309i      1.0789       0.1769
## 1+0.1251B+1.0567B^2   -0.0592+-0.9710i      1.0280       0.2597
## 1+0.8970B+1.0497B^2   -0.4273+-0.8775i      1.0246       0.3221
## 1+0.5467B+1.0462B^2   -0.2613+-0.9421i      1.0228       0.2931
## 1+1.0203B             -0.9769               1.0220       0.4909
## 1+1.0203B             -0.9769               1.0220       0.4909
## 1+1.7854B+1.0425B^2   -0.8564+-0.4753i      1.0210       0.4194
## 1-1.3765B+1.0412B^2    0.6610+-0.7235i      1.0204       0.1322
## 1+0.8316B+1.0397B^2   -0.3999+-0.8955i      1.0197       0.3168
## 1+1.1049B+1.0386B^2   -0.5319+-0.8245i      1.0191       0.3412
## 1-0.0523B+1.0363B^2    0.0252+-0.9820i      1.0180       0.2459
## 1-0.1960B+1.0325B^2    0.0949+-0.9795i      1.0161       0.2346
## 1-0.7228B+1.0309B^2    0.3506+-0.9204i      1.0153       0.1921
## 1+0.4165B+1.0132B^2   -0.2055+-0.9720i      1.0066       0.2832
## 1-1.0839B+1.0119B^2    0.5356+-0.8375i      1.0059       0.1594
## 1+1.5355B+1.0112B^2   -0.7592+-0.6422i      1.0056       0.3883
## 1-0.3884B+1.0110B^2    0.1921+-0.9758i      1.0055       0.2191
## 1+1.8976B+1.0105B^2   -0.9389+-0.3286i      1.0053       0.4464
## 1-0.6185B+1.0095B^2    0.3063+-0.9470i      1.0047       0.2002
## 1+0.9673B             -0.9583               1.0047       0.4564
## 1+0.9673B             -0.9583               1.0047       0.4564
## 1+0.9850B             -0.9786               1.0033       0.4696
## 1+0.9850B             -0.9786               1.0033       0.4696
## 1+0.8669B             -0.8617               1.0030       0.4161
## 1+0.8669B             -0.8617               1.0030       0.4161
## 1-0.6917B              0.6877               1.0029       0.1289
## 1-0.6917B              0.6877               1.0029       0.1289
## 1+1.4401B+1.0054B^2   -0.7162+-0.6941i      1.0027       0.3775
## 1+0.9941B             -0.9888               1.0026       0.4792
## 1-0.5512B              0.5483               1.0026       0.1574
## 1-0.5512B              0.5484               1.0026       0.1574
## 1+0.9939B             -0.9890               1.0025       0.4792
## 1+0.9282B             -0.9239               1.0023       0.4384
## 1+0.9282B             -0.9239               1.0023       0.4384
## 1-0.5024B+1.0040B^2    0.2502+-0.9661i      1.0020       0.2097
## 1-0.3086B+1.0030B^2    0.1539+-0.9866i      1.0015       0.2254
## 1-0.9502B+1.0029B^2    0.4737+-0.8790i      1.0015       0.1713
## 1+0.5890B+1.0026B^2   -0.2937+-0.9545i      1.0013       0.2975
## 1-0.7074B              0.7058               1.0011       0.1251
## 1+1.1707B+1.0017B^2   -0.5843+-0.8104i      1.0009       0.3494
## 1+0.7053B+1.0001B^2   -0.3526+-0.9357i      1.0000       0.3074
## 1+1.3455B+0.9993B^2   -0.6732+-0.7399i      0.9997       0.3675
## 1+1.7848B+0.9993B^2   -0.8930+-0.4508i      0.9996       0.4256
## 1+1.5415B+0.9992B^2   -0.7714+-0.6370i      0.9996       0.3901
## 1+1.8385B+0.9989B^2   -0.9202+-0.3928i      0.9995       0.4358
## 1+0.9679B             -0.9689               0.9995       0.4599
## 1+0.9678B             -0.9689               0.9994       0.4599
## 1+1.0414B+0.9987B^2   -0.5214+-0.8541i      0.9993       0.3372
## 1+0.9475B+0.9985B^2   -0.4745+-0.8811i      0.9992       0.3286
## 1+0.9847B+0.9984B^2   -0.4932+-0.8709i      0.9992       0.3320
## 1+1.8081B+0.9978B^2   -0.9061+-0.4257i      0.9989       0.4301
## 1+1.2852B+0.9969B^2   -0.6446+-0.7665i      0.9985       0.3613
## 1+0.8832B+0.9966B^2   -0.4431+-0.8984i      0.9983       0.3229
## 1-0.8077B+0.9964B^2    0.4053+-0.9162i      0.9982       0.1837
## 1+1.3756B+0.9963B^2   -0.6903+-0.7261i      0.9981       0.3710
## 1-0.5647B+0.9961B^2    0.2834+-0.9610i      0.9980       0.2044
## 1+0.2185B+0.9959B^2   -0.1097+-0.9960i      0.9980       0.2675
## 1+0.2745B+0.9954B^2   -0.1379+-0.9928i      0.9977       0.2720
## 1+0.8469B             -0.8509               0.9977       0.4114
## 1+0.8469B             -0.8509               0.9977       0.4114
## 1-0.7082B              0.7116               0.9976       0.1244
## 1+0.8708B             -0.8751               0.9975       0.4189
## 1+0.8708B             -0.8751               0.9975       0.4189
## 1-1.1514B+0.9946B^2    0.5788+-0.8188i      0.9973       0.1521
## 1+0.9748B             -0.9801               0.9973       0.4661
## 1+0.9748B             -0.9801               0.9973       0.4661
## 1-0.3349B+0.9944B^2    0.1684+-0.9886i      0.9972       0.2231
## 1+1.4257B+0.9934B^2   -0.7176+-0.7012i      0.9967       0.3768
## 1+0.6217B+0.9923B^2   -0.3133+-0.9538i      0.9961       0.3005
## 1+0.9958B             -1.0042               0.9958       0.5000
## 1+1.5743B+0.9915B^2   -0.7939+-0.6150i      0.9958       0.3951
## 1-1.5278B+0.9914B^2    0.7705+-0.6442i      0.9957       0.1108
## 1+1.6047B+0.9910B^2   -0.8096+-0.5946i      0.9955       0.3992
## 1+0.8171B             -0.8249               0.9953       0.4033
## 1+0.8171B             -0.8249               0.9953       0.4033
## 1+0.9825B             -0.9920               0.9952       0.4746
## 1+0.9825B             -0.9921               0.9952       0.4746
## 1-0.6581B              0.6646               0.9950       0.1350
## 1-0.7392B              0.7467               0.9950       0.1167
## 1+0.1777B+0.9898B^2   -0.0898+-1.0011i      0.9949       0.2642
## 1-0.5889B              0.5951               0.9947       0.1492
## 1+0.0183B+0.9895B^2   -0.0092+-1.0053i      0.9947       0.2515
## 1+0.5267B+0.9892B^2   -0.2662+-0.9696i      0.9946       0.2926
## 1-0.5886B              0.5952               0.9945       0.1492
## 1-0.6562B              0.6638               0.9942       0.1353
## 1-1.0274B+0.9884B^2    0.5197+-0.8612i      0.9942       0.1636
## 1+0.5974B             -0.6047               0.9940       0.3526
## 1+0.5974B             -0.6047               0.9940       0.3526
## 1-1.2816B+0.9879B^2    0.6487+-0.7691i      0.9939       0.1385
## 1+1.4765B+0.9871B^2   -0.7478+-0.6736i      0.9935       0.3833
## 1-0.0698B+0.9869B^2    0.0353+-1.0060i      0.9934       0.2444
## 1-1.4544B+0.9868B^2    0.7369+-0.6858i      0.9934       0.1193
## 1+0.9873B             -1.0014               0.9930       0.4831
## 1+0.9873B             -1.0015               0.9929       0.4831
## 1+0.2217B             -0.2250               0.9927       0.2859
## 1+0.2217B             -0.2250               0.9927       0.2859
## 1+1.0855B+0.9848B^2   -0.5511+-0.8436i      0.9924       0.3421
## 1-0.9021B+0.9848B^2    0.4580+-0.8976i      0.9924       0.1749
## 1+0.8316B             -0.8445               0.9924       0.4081
## 1+0.8316B             -0.8445               0.9923       0.4081
## 1-0.9877B+0.9814B^2    0.5032+-0.8751i      0.9906       0.1669
## 1-0.2484B+0.9812B^2    0.1266+-1.0016i      0.9906       0.2300
## 1+0.9895B             -1.0087               0.9905       0.4932
## 1-0.6443B+0.9809B^2    0.3284+-0.9548i      0.9904       0.1973
## 1+0.9894B             -1.0088               0.9903       0.4932
## 1-0.0625B              0.0637               0.9902       0.2399
## 1-0.0625B              0.0637               0.9902       0.2399
## 1-0.7381B              0.7529               0.9901       0.1161
## 1-0.7741B              0.7900               0.9898       0.1071
## 1+0.0737B+0.9791B^2   -0.0376+-1.0099i      0.9895       0.2559
## 1-0.8418B+0.9790B^2    0.4299+-0.9147i      0.9894       0.1801
## 1+0.7624B+0.9788B^2   -0.3895+-0.9327i      0.9893       0.3130
## 1+0.3629B+0.9777B^2   -0.1856+-0.9941i      0.9888       0.2794
## 1+0.3268B+0.9775B^2   -0.1672+-0.9975i      0.9887       0.2764
## 1-0.7733B+0.9745B^2    0.3967+-0.9321i      0.9872       0.1860
## 1+1.8763B+0.9744B^2   -0.9628+-0.3151i      0.9871       0.4497
## 1+0.1190B+0.9742B^2   -0.0611+-1.0113i      0.9870       0.2596
## 1+0.9222B             -0.9478               0.9864       0.4423
## 1+0.9222B             -0.9478               0.9864       0.4423
## 1+1.1153B+0.9727B^2   -0.5733+-0.8363i      0.9863       0.3456
## 1+1.9286B+0.9713B^2   -0.9928+-0.2095i      0.9855       0.4669
## 1-0.6033B              0.6218               0.9850       0.1451
## 1-0.6042B              0.6229               0.9849       0.1449
## 1-0.7066B+0.9698B^2    0.3643+-0.9478i      0.9848       0.1916
## 1+1.2326B+0.9687B^2   -0.6362+-0.7922i      0.9842       0.3577
## 1+1.2884B+0.9685B^2   -0.6651+-0.7682i      0.9841       0.3636
## 1-0.1965B+0.9685B^2    0.1015+-1.0111i      0.9841       0.2341
## 1-0.4304B+0.9658B^2    0.2228+-0.9928i      0.9828       0.2149
## 1-0.6153B              0.6377               0.9823       0.1423
## 1+1.5442B+0.9642B^2   -0.8007+-0.6292i      0.9820       0.3940
## 1+1.8877B+0.9641B^2   -0.9790+-0.2808i      0.9819       0.4555
## 1-0.6150B              0.6390               0.9811       0.1422
## 1+0.9789B             -1.0187               0.9803       0.4916
## 1+0.9788B             -1.0189               0.9801       0.4916
## 1+0.9718B             -1.0220               0.9751       0.4868
## 1+0.9718B             -1.0220               0.9751       0.4868
## 1+0.6745B+0.9500B^2   -0.3550+-0.9626i      0.9747       0.3062
## 1-0.4410B+0.9489B^2    0.2324+-0.9999i      0.9741       0.2137
## 1+0.7812B+0.9430B^2   -0.4142+-0.9428i      0.9711       0.3159
## 1+1.7627B+0.9383B^2   -0.9393+-0.4283i      0.9686       0.4319
## 1-0.6968B              0.7471               0.9657       0.1217
## 1-0.6952B              0.7476               0.9643       0.1219
##   
## 
#Transform  data with “seasonal difference”, which appears to be stationary, we'll find a stationary model for this realization
x=data$gdp.change
# difference the data
d1=artrans.wge(x,phi.tr=1)

#we try seasonal model with s=27
d1.27=artrans.wge(d1,phi.tr = c(rep(0,28),1))

#Use tswge to model the transformed data, d1.27
aic5.wge(d1.27,p=0:5,q=0:5)
## ---------WORKING... PLEASE WAIT... 
## 
## 
## Five Smallest Values of  aic
##       p    q        aic
## 31    5    0   3.249695
## 21    3    2   3.280678
## 2     0    1   3.296534
## 20    3    1   3.307900
## 33    5    2   3.320749
# aic picks an ARMA(5,0) as the first choice
#In order to see if a lower order model could satisfactorily model the data, we use BIC
aic5.wge(d1.27,p=0:5,q=0:5,type='bic')
## ---------WORKING... PLEASE WAIT... 
## 
## 
## Five Smallest Values of  bic
##       p    q        bic
## 2     0    1   3.323773
## 31    5    0   3.331413
## 21    3    2   3.362396
## 20    3    1   3.375998
## 7     1    0   3.382539
#BIC picks ARMA(5,0) as the second choice,We decide to use the ARMA(5,0) model chosen by AIC and BIC
# AIC and BIC picks p=1,q=5
fitaruma=arima(data$gdp.change,order=c(5,1,0),xreg=cbind(data$GDP.per.capita,data$Income.receipt,data$gross.income))
fitaruma
## 
## Call:
## arima(x = data$gdp.change, order = c(5, 1, 0), xreg = cbind(data$GDP.per.capita, 
##     data$Income.receipt, data$gross.income))
## 
## Coefficients:
##           ar1      ar2      ar3      ar4      ar5
##       -0.3347  -0.0760  -0.1244  -0.1650  -0.1641
## s.e.   0.0801   0.0793   0.0707   0.0671   0.0638
##       cbind(data$GDP.per.capita, data$Income.receipt, data$gross.income)1
##                                                                   -0.0082
## s.e.                                                               0.0015
##       cbind(data$GDP.per.capita, data$Income.receipt, data$gross.income)2
##                                                                    0.0045
## s.e.                                                               0.0107
##       cbind(data$GDP.per.capita, data$Income.receipt, data$gross.income)3
##                                                                    0.0177
## s.e.                                                               0.0036
## 
## sigma^2 estimated as 12.25:  log likelihood = -777.6,  aic = 1573.2
AIC(fitarima) 
## [1] 1572.964
#We estimate the parameters of the ARMA(5,0) model using est.ar.wge
x_27_arma=est.ar.wge(d1.27, p=5)
## 
## Coefficients of Original polynomial:  
## -0.4983 -0.2426 -0.2040 -0.2243 -0.3041 
## 
## Factor                 Roots                Abs Recip    System Freq 
## 1+0.8053B             -1.2418               0.8053       0.5000
## 1+0.7199B+0.6155B^2   -0.5848+-1.1326i      0.7845       0.3259
## 1-1.0268B+0.6135B^2    0.8369+-0.9642i      0.7833       0.1362
##   
##   
## 
## Coefficients of Original polynomial:  
## -0.4983 -0.2426 -0.2040 -0.2243 -0.3041 
## 
## Factor                 Roots                Abs Recip    System Freq 
## 1+0.8053B             -1.2418               0.8053       0.5000
## 1+0.7199B+0.6155B^2   -0.5848+-1.1326i      0.7845       0.3259
## 1-1.0268B+0.6135B^2    0.8369+-0.9642i      0.7833       0.1362
##   
## 
ljung.wge(x_27_arma$res)
## Obs -0.02907963 -0.04995584 -0.05843614 -0.07108814 -0.05051819 -0.08992947 -0.07447575 -0.1034145 0.03947868 0.1472326 0.0773277 -0.07160113 -0.2103733 0.06884934 -0.1227055 0.04381979 0.06580372 -0.04145771 -0.02393789 0.1137795 0.06583719 -0.001061071 -0.09334691 0.0520115
## $test
## [1] "Ljung-Box test"
## 
## $K
## [1] 24
## 
## $chi.square
## [1] 48.38316
## 
## $df
## [1] 24
## 
## $pval
## [1] 0.002262275
ljung.wge(x_27_arma$res, K = 48)
## Obs -0.02907963 -0.04995584 -0.05843614 -0.07108814 -0.05051819 -0.08992947 -0.07447575 -0.1034145 0.03947868 0.1472326 0.0773277 -0.07160113 -0.2103733 0.06884934 -0.1227055 0.04381979 0.06580372 -0.04145771 -0.02393789 0.1137795 0.06583719 -0.001061071 -0.09334691 0.0520115 0.03694837 0.01176635 0.01150009 0.1051457 -0.34304 -0.08880146 0.08546404 0.03038385 -0.0635886 0.03251928 0.02566841 0.02564567 0.05714387 -0.001871735 -0.1185075 -0.06928661 -0.02930197 0.2215155 -0.05000339 -0.01698825 0.08460033 0.001409524 0.07677338 0.04896264
## $test
## [1] "Ljung-Box test"
## 
## $K
## [1] 48
## 
## $chi.square
## [1] 122.2092
## 
## $df
## [1] 48
## 
## $pval
## [1] 2.131004e-08
f_x27arma = fore.aruma.wge(data$gdp.change,s = 27,phi =x_27_arma$phi,n.ahead =12,limits = F, lastn = T)

f_x27armashort = fore.aruma.wge(data$gdp.change,s = 27,phi =x_27_arma$phi,n.ahead =2,limits = F, lastn = T)

ASE_x27arma= mean((data$gdp.change[(length(x)-11):length(x)] - f_x27arma$f)^2)

ASE_x27arma
## [1] 6.365055
ASE_x27arma_short= mean((data$gdp.change[(length(x)-1):length(x)] - f_x27armashort$f)^2)

ASE_x27arma_short
## [1] 14.18755
#Compare Spectral Densities
sims = 5
SpecDen = parzen.wge(data$gdp.change, plot = "FALSE")
plot(SpecDen$freq,SpecDen$pzgram, type = "l", lwd = 6)

for( i in 1: sims)
{
   SpecDen4 = parzen.wge(gen.aruma.wge(297, phi = x_27_arma$phi,s=27, plot ="FALSE"), plot = "FALSE")
   lines(SpecDen4$freq,SpecDen4$pzgram, lwd = 2, col = "red")
}

#Compare ACFs
sims = 5
ACF = acf(data$gdp.change, plot = "FALSE")
plot(ACF$lag ,ACF$acf , type = "l", lwd = 6)

for( i in 1: sims)
{
   ACF5 = acf(gen.aruma.wge(297, phi = x_27_arma$phi,s=27, plot = "FALSE"), plot = "FALSE")
   lines(ACF5$lag ,ACF5$acf, lwd = 2, col = "red")
}

Multivariate analysis: VAR Model

data2 = data[1:292,]
gdpVar1 =VAR(cbind(data2$gdp.change,data2$GDP.per.capita,data2$Income.receipt), type="both", lag.max = 10)
## Warning in VAR(cbind(data2$gdp.change, data2$GDP.per.capita, data2$Income.receipt), : No column names supplied in y, using: y1, y2, y3 , instead.
AIC(gdpVar1)  #7177.838
## [1] 7342.273
preds_short = predict(gdpVar1,n.ahead = 2)
ASE_var1_st = mean((data$gdp.change[291:292] - preds_short$fcst$y1[,1])^2)
ASE_var1_st  #ASE for VAR model is 9.952455
## [1] 18.07533
plot(seq(1,292,1), data$gdp.change[1:292], type = "l",xlim = c(0,292), ylab = "gdp change", main = "Short_term gdp change Forecast")
lines(seq(291,292,1), preds_short$fcst$y1[,1], type = "l", col = "red")

# VAR Model long-term forecast last 24 with much less ASE and AIC than short-term
data2 = data[1:268,]
gdpVar1 = VAR(cbind(data2$gdp.change,data2$GDP.per.capita,data2$Income.receipt), type="both", lag.max = 10)
## Warning in VAR(cbind(data2$gdp.change, data2$GDP.per.capita, data2$Income.receipt), : No column names supplied in y, using: y1, y2, y3 , instead.
AIC(gdpVar1)  
## [1] 6623.122
preds = predict(gdpVar1,n.ahead = 24)
ASEvar_lt=mean((data$gdp.change[269:292] - preds$fcst$y1[,1])^2)
ASEvar_lt 
## [1] 3.989787
plot(seq(1,292,1), data$gdp.change[1:292], type = "l",xlim = c(0,292), ylab = "gdp change", main = "Long_term gdp change Forecast")
lines(seq(269,292,1), preds$fcst$y1[,1], type = "l", col = "red")

Multivariate analysis:Neural network

# MLP fit with 5 hidden nodes and 20 repetitions.
gdp.change=ts(data2$gdp.change)
GDP.per.capita=ts(data2$GDP.per.capita)
Income.receipt=ts(data2$Income.receipt)
xVar=data.frame(GDP.per.capita,Income.receipt)
set.seed(2)
fit.mlp=mlp(gdp.change,xreg=xVar)
fit.mlp
## MLP fit with 5 hidden nodes and 20 repetitions.
## Univariate lags: (1,2,3,4)
## 2 regressors included.
## - Regressor 1 lags: (2,4)
## - Regressor 2 lags: (2,3)
## Forecast combined using the median operator.
## MSE: 7.5201.
## MLP fit with 5 hidden nodes and 20 repetitions, forecast combined using the median operator, MSE=7.08
xVar1=data.frame(GDP.per.capita=ts(data$GDP.per.capita),Income.receipt=ts(data$Income.receipt))
plot(fit.mlp)

## short-term forecast
fore.mlp_short = forecast(fit.mlp, h=2,  xreg = xVar1)
plot(fore.mlp_short)

ASE_nn_st = mean((data$gdp.change[291:292] - fore.mlp_short$mean)^2)
ASE_nn_st  
## [1] 15.1618
#Plot short_term forecast
plot(seq(1,292,1), data$gdp.change, type = "l",xlim = c(0,295), ylab = "gdp change", main = "Short_term GDP.Change Forecast from MLP")
lines(seq(291,292,1), fore.mlp_short$mean, type = "l", col = "red")

## long-term forecast
fore.mlp = forecast(fit.mlp, h=24,  xreg = xVar1)
plot(fore.mlp)

ASE_nn_lt= mean((data$gdp.change[269:292] - fore.mlp$mean)^2)
ASE_nn_lt  
## [1] 6.928138
#Plot long_term forecast
plot(seq(1,292,1), data$gdp.change, type = "l",xlim = c(0,295), ylab = "gdp change", main = "Long_term  GDP.Change Forecast from MLP")
lines(seq(269,292,1), fore.mlp$mean, type = "l", col = "red")

Ensemble model

# long term ensemble 
ensemble  = (preds$fcst$y1[,1] + fore.mlp$mean)/2

#Plot
plot(seq(1,292,1), data$gdp.change, type = "l",xlim = c(0,292),  ylab = "gdp change", main = "Ensemble model long-term Forecast")
lines(seq(269,292,1), y=ensemble, type = "l", col = "RED")

ASE_ensemble = mean((data$gdp.change[269:292] - ensemble)^2)
ASE_ensemble  
## [1] 4.783706
## short term ensemble model
ensemble  = (preds_short$fcst$y1[,1] + fore.mlp_short$mean)/2

#Plot
plot(seq(1,292,1), data$gdp.change, type = "l",xlim = c(0,292),  ylab = "gdp change", main = "Ensemble model GDP.Change Forecast")
lines(seq(291,292,1), y=ensemble, type = "l", col = "RED")

ASE_ensemble = mean((data$gdp.change[291:292] - ensemble)^2)
ASE_ensemble  #4.8
## [1] 16.25906

Model Comparison

#For the short-term forecast, we may see ARIMA(5,1,0)  with s=27 shows better performance with lowest ASE 14.18755;
#For the long-term forecast, the ensemble model shows the better performance with the lowest ASE 4.78.

print(' *ARMA(4,3)      Short-term ASE 37.968,  Long-term ASE 6.879'  )
## [1] " *ARMA(4,3)      Short-term ASE 37.968,  Long-term ASE 6.879"
print(' *ARIMA(5,1)     Short-term ASE 35.09,   Long-term ASE 6.515'  )
## [1] " *ARIMA(5,1)     Short-term ASE 35.09,   Long-term ASE 6.515"
print(' *ARUMA(5,1,0)   Short-term ASE 14.187,  Long-term ASE 6.365'  )
## [1] " *ARUMA(5,1,0)   Short-term ASE 14.187,  Long-term ASE 6.365"
print(' *VAR            Short-term ASE 25.895,  Long-term ASE 5.15'  )
## [1] " *VAR            Short-term ASE 25.895,  Long-term ASE 5.15"
print(' *MLP            Short-term ASE 15.16,   Long-term ASE 6.27'  )
## [1] " *MLP            Short-term ASE 15.16,   Long-term ASE 6.27"
print(' *Ensemble       Short-term ASE 16.259,  Long-term ASE 4.78'  )
## [1] " *Ensemble       Short-term ASE 16.259,  Long-term ASE 4.78"

Summary

  • GDP data is very difficult to predict, and models are not able to capture variance in this data.
  • For the short-term forecast, we may see ARIMA(5,1,0) with s=27 shows better performance with lowest ASE 14.18755;
  • For the long-term forecast, the ensemble model shows the better performance with the lowest ASE 4.78.
  • After all, we can’t simply say which model is better than the other as they perform differently in the different periods.